#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using minheap = priority_queue<int, vector<int>, greater<int>>;

const int N = 110;

int t;
int n, m;

string s[N];
int main() {
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    cin >> t;
    while (t--) {
        cin >> n >> m;
        minheap q;

        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= m; j++) {
                int x1 = abs(i-1)+abs(j-1);
                int x2 = abs(i-n)+abs(j-m);
                int x3 = abs(i-1)+abs(j-m);
                int x4 = abs(i-n)+abs(j-1);

                q.push(max({x1, x2, x3, x4}));
            }
        }

        while(!q.empty()) {
            cout << q.top() << ' ';
            q.pop();
        }
        cout << endl;
    }
    return 0;
}